import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch, Redirect } from 'react-router-dom';
import { getCookie } from './common/cookies';
import PageApp from './App';
import PageLogin from './pages/Login/Login'

export default class Routes extends Component {
  requireAuth = (Layout, props) => {
    if (!getCookie('TOKEN')) {
      return <Redirect to="/login" />
    } else return <Layout {...props} />
  }

  render() {
    return (
      <Router>
        <Switch>
          <Route path="/login" exact component={ PageLogin } />
          <Route path="/" component={ props => this.requireAuth(PageApp, props)  } />
        </Switch>
      </Router>
    );
  }
}
